/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */

package cn.edu.thu.log.util;

import java.util.ArrayList;
import java.util.List;
import org.deckfour.xes.classification.XEventAttributeClassifier;
import org.deckfour.xes.extension.XExtension;
import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.factory.XFactory;
import org.deckfour.xes.factory.XFactoryRegistry;
import org.deckfour.xes.info.XLogInfo;
import org.deckfour.xes.info.XLogInfoFactory;
import org.deckfour.xes.model.XAttribute;
import org.deckfour.xes.model.XLog;
import storage.dbhelper.LogHeadHelper;
import storage.dbobject.DbLogHead;
/**
 * 
 * @author dongzihe
 *
 */
public final class GenaralLogOperation {
	
	private GenaralLogOperation() {
		super();
	}

	/**
	 * @param log parameter
	 */
	public static void setupBasicAttributes(XLog log) {
		setupClassifier(log);
		setupGlobalAttributes(log);
		setupExtensions(log);
	}

	/**
	 * set up classifier for log
	 */
	private static void setupClassifier(XLog log) {
		String[] keys = { XConceptExtension.KEY_NAME };
		XEventAttributeClassifier classifier;
		classifier = new XEventAttributeClassifier("activity classifier", keys);
		log.getClassifiers().add(classifier);

	}

	// set up extensions for log
	private static void setupExtensions(XLog log) {
		XExtension timeExtension = XTimeExtension.instance();
		XExtension conceptExtension = XConceptExtension.instance();
		log.getExtensions().add(timeExtension);
		log.getExtensions().add(conceptExtension);

	}

	// set up global attributes
	private static void setupGlobalAttributes(XLog log) {
		XFactory factory = XFactoryRegistry.instance().currentDefault();
		XAttribute attributeConcept = factory.createAttributeLiteral(
				XConceptExtension.KEY_NAME, "name", null);
		log.getGlobalEventAttributes().add(attributeConcept);
		XAttribute attributeTime = factory.createAttributeLiteral(
				XTimeExtension.KEY_TIMESTAMP, "time", null);
		log.getGlobalEventAttributes().add(attributeTime);

		log.getGlobalTraceAttributes().add(attributeConcept);
	}
/**
 * 
 * @param log parameter
 * @param xesName parameter
 */
	public static void writeLogToXES(XLog log, String xesName) {

	}

	/**
	 * get teh location of content in logHead
	 * 
	 * @param tagLocation the location of the tag in tagList
	 * @param logHeadTagList parameter
	 * @return the location of content in contentList in logHead
	 */
	public static int getLogHeadLoc(int tagLocation,
			ArrayList<String> logHeadTagList) {
		LogHeadHelper logHeadH = new LogHeadHelper();
		List<DbLogHead> logHeadTags = logHeadH.getLogHeads(DbLogHead.CL_NAME,
				logHeadTagList.get(tagLocation));
		DbLogHead logHeadTag = logHeadTags.get(0);
		String locString = logHeadTag.getLocation();

		int loc = Integer.parseInt(locString) - 1;
		return loc;
	}
/**
 * 
 * @param logL parameter
 * @return
 */
	public static int getLogEventSize(XLog logL) {
		int events = 0;
		XLogInfo info = null;
		info = XLogInfoFactory.createLogInfo(logL);
		events += info.getNumberOfEvents();
		return events;
	}
}
